// Cheshire Cat
// by lord Kelvin
#include <dos.h>
#include <math.h>
#include <conio.h>

char sm[ 3 ] = { 'B', 'H', '$' };
unsigned char * scr = ( unsigned char * ) 0xA0000000L;

float inline sqr( float a )
{
	return a * a;
}

void spal()
{
	outp( 0x3C8, 0 );
	for( int N = 0; N < 256 * 3; N++ )
		outp( 0x3C9, ( int )( sqr( sin( N * 21167.0 ) ) * 64. ) );
}

void main()
{
	asm mov ax,0x13
	asm int 0x10

		spal();

	asm mov dx,offset sm
	asm mov ah,9
	asm int 0x21

	for( int y = 199; y >= 0 ; y-- )
		for( int x = 319; x >= 0; x-- )
			scr[ x + 48 + 320u * ( y + 4 ) ] =
				scr[ y / 13 + x / 32 * 320u ] ? 224 : 0;

	while( !kbhit() )
	{
		for( y = 0; y < 200 ; y++ )
			for( int x = 0; x < 320; x++ )
		{
			unsigned int i = x + 320u * y;
			scr[ i ] = ( scr[ i - 320 ] + scr[ i - 1 ] +
				scr[ i + 1 ] + scr[ i + 320 ] ) / 4;
		}
	}

	asm mov ax,0x3
	asm int 0x10
}